package com.tianyang.yukuaifu.business.main.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.business.main.bean.DeviceOutput;
import com.tianyang.yukuaifu.utils.VerifyUtil;

import java.util.ArrayList;

/**
 * Description：码牌/音响列表
 * Created by xyj on 2024/4/21
 */
public class CodePlateListAdapter extends BaseQuickAdapter<DeviceOutput, BaseViewHolder> {

    private String deviceType;

    public CodePlateListAdapter(String deviceType) {
        super(R.layout.item_code_plate, new ArrayList<>());
        this.deviceType = deviceType;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, DeviceOutput item) {
        if (item != null) {
            helper.setText(R.id.posNameTv, VerifyUtil.checkString(item.getPosName()))
                    .setText(R.id.posModelTv, "设备类型："+VerifyUtil.checkString(item.getPosModel()))
                    .setText(R.id.posNumberTv, "SN："+VerifyUtil.checkString(item.getPosNumber()))
                    .setText(R.id.bindPosNumberTv, "关联音响SN："+VerifyUtil.checkString(item.getBindPosNumber()))
                    .addOnClickListener(R.id.modifyRtv)
                    .addOnClickListener(R.id.relationRtv)
                    .addOnClickListener(R.id.unRelationRtv)
                    .addOnClickListener(R.id.takeCodeRtv);

            TextView isRelationTv = helper.getView(R.id.isRelationTv);
            TextView bindPosNumberTv = helper.getView(R.id.bindPosNumberTv);
            TextView relationRtv = helper.getView(R.id.relationRtv);
            TextView unRelationRtv = helper.getView(R.id.unRelationRtv);
            if (TextUtils.equals("CODE_PLATE", deviceType)) {
                isRelationTv.setVisibility(View.VISIBLE);
                if (TextUtils.equals("Y", item.getIzRelation())) {
                    isRelationTv.setText("已关联");
                    isRelationTv.setBackgroundResource(R.drawable.img_auth_status_check);
                    bindPosNumberTv.setVisibility(View.VISIBLE);
                    relationRtv.setVisibility(View.GONE);
                    unRelationRtv.setVisibility(View.VISIBLE);
                } else {
                    isRelationTv.setText("未关联");
                    isRelationTv.setBackgroundResource(R.drawable.img_auth_status_normal);
                    bindPosNumberTv.setVisibility(View.GONE);
                    relationRtv.setVisibility(View.VISIBLE);
                    unRelationRtv.setVisibility(View.GONE);
                }
            } else {
                isRelationTv.setVisibility(View.GONE);
            }
        }
    }
}
